// uecgi_network.cpp
#include <winsock2.h>

// UELogger Support
#include "litelog.h"
extern "C" extern int logfd;

// API declaration
#include "uecgi_network.h"

int InitWinSock2()
{
	WORD wVersionRequested;
	WSADATA wsaData;

	wVersionRequested = MAKEWORD( 2, 2 );

	dbglog("Initialize windows socket", DEBUG_LOG_LEVEL_INFO, logfd, __FILE__, __LINE__);

	if ( WSAStartup( wVersionRequested, &wsaData ) != 0 ) {
		/* Tell the user that we could not find a usable */
		/* WinSock DLL.                                  */
		dbglog("Failed to initialize windows socket", DEBUG_LOG_LEVEL_ERRO, logfd, __FILE__, __LINE__);

		return 0;
	}
	 
	/* Confirm that the WinSock DLL supports 2.2.*/
	/* Note that if the DLL supports versions greater    */
	/* than 2.2 in addition to 2.2, it will still return */
	/* 2.2 in wVersion since that is the version we      */
	/* requested.                                        */
	if ( LOBYTE( wsaData.wVersion ) != 2 ||
			HIBYTE( wsaData.wVersion ) != 2 ) {
		/* Tell the user that we could not find a usable */
		/* WinSock DLL.                                  */
		dbglog("Incompatable windows socket version", DEBUG_LOG_LEVEL_ERRO, logfd, __FILE__, __LINE__);
		WSACleanup( );
		return 0; 
	}

	return 1;
}